Is it possible to output ReqEnd using std.log in VCL? I would like to use ReqEnd in varnishncsa logging.
I don't know if you can log ReqEnd in varnishnsca but you can log the request start time and xid.
vcl example:
........
C{
#include <syslog.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
}C
sub vcl_recv {
C{
struct timeval detail_time;
gettimeofday(&detail_time,NULL);
char start[20];
sprintf(start, "%lu%06lu", detail_time.tv_sec, detail_time.tv_usec);
VRT_SetHdr(sp, HDR_REQ, "\020X-Request-Start:", start, vrt_magic_string_end);
}C
........
sub vcl_deliver {
set resp.http.X-ID = req.xid;
}
.......
and you can see it: varnishncsa -F "%{X-Request-Start}o %{X-ID}o"
Related
I am getting compilation error:error: ‘scmp_filter_ctx’ was not declared in this scope.
I have declared a seccomp filter.
scmp_filter_ctx ctx;
I have included the library #include <linux/seccomp.h>
and already installed the library libseccomp-dev using
sudo apt-get install libseccomp-dev.
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <unistd.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <bits/stdc++.h>
void create_sandbox(){
scmp_filter_ctx ctx;
ctx = seccomp_init(SCMP_ACT_KILL); // default action: kill
seccomp_load(ctx);
}
I managed to solve this error using the following:
Replaced #include <linux/seccomp.h> with #include <seccomp.h>
and while compiling, used g++ filename.cpp -lseccomp.
This worked for me.
I wonder to understand where fcntl c++ function saves information about locked files. I know that it saves some information on /proc/locks , but fcntl identify lock even if it locked by another host
In my first host I locked some file By F_WRLCK.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include<iostream>
main() {
int fd;
struct flock lock;
lock.l_type=F_WRLCK;
lock.l_start=0;
lock.l_whence= SEEK_SET;
lock.l_len=0;
printf("open %d\n",fd=open("/u/embedit/places/scratch/gtevos/ts16nxq42p11assrl16kaa03/ts16nxq42p11assrl16kaa.cpj", O_RDWR ));
int rc = fcntl(fd, F_SETLK, &lock);
std::cout<<rc<<std::endl;
std::cin>>fd;
}
When I am traying to lock the same file on my second host by F_RDONLY it doesn't work.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include<iostream>
main() {
int fd;
struct flock lock;
lock.l_type=F_RDLCK;
lock.l_start=0;
lock.l_whence= SEEK_SET;
lock.l_len=0;
printf("open %d\n",fd=open("/u/embedit/places/scratch/gtevos/ts16nxq42p11assrl16kaa03/ts16nxq42p11assrl16kaa.cpj", O_RDONLY ));
int rc = fcntl(fd, F_SETLK, &lock);
std::cout<<rc<<std::endl;
std::cin>>fd;
}
I just want to understand which mechanism is used that provide ability to right identify locks.
I'm trying to print the value of CLOCK_TICK_RATE with the following program:
#include <fcntl.h>
#include <getopt.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/kd.h>
#include <linux/timex.h>
int main() {
printf("%d\n",CLOCK_TICK_RATE);
}
I get an compilation error:
error: ‘CLOCK_TICK_RATE’ undeclared.
I looked for the definition of CLOCK_TICK_RATE, I found that in timex.h, but even after I included timex.h CLOCK_TICK_RATE is still undeclared.
thanks in advance.
Maybe you are looking for this?
#include <stdio.h>
#include <unistd.h>
int main (void) {
printf (
"%ld\n",
sysconf(_SC_CLK_TCK)
);
return 0;
}
It's in hertz and is normally 100.
I need to dns over ssl. DNS queryis UDP packeted and I need to change it to SSL protocol?
It is working in linux.
How does ubuntu 12.04 resolves dns and how to change to SSL?
I have tried create ssl socket and send dns queryis.
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <resolv.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <netdb.h>
#include <openssl/rsa.h>
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
//#include "server.h"
#define FAIL -1
void initChild(int cli, SSL_CTX* ctx);
void error(const char *msg) {
perror(msg);
exit(1);
}
int main(int count, char *strings[]) {
SSL_CTX *ctx;
int server;
char *portnum;
SSL* ssl;
int cli;
struct hostent *hp;
int pid;
if (count != 2)
{
printf("Usage: %s <portnum>\n", strings[0]);
exit(0);
}
SSL_library_init();
portnum = strings[1];
ctx = InitServerCTX();
LoadCertificates(ctx, "ser-cert.pem", "ser-key.pem");
server = OpenListener(atoi(portnum));
while (1) {
struct sockaddr_in addr;
int len = sizeof(addr);
int cli = accept(server, (struct sockaddr*)&addr, &len);
if (!(pid = fork())) {
//Child process
//close(server);
initChild(cli, ctx);
exit(0);
}
else if (pid > 0) {
//Parent process
}
else {
printf("Fork failed!!");
//close(server);
}
}
close(server);
SSL_CTX_free(ctx);
return 0;
}
void initChild(int cli, SSL_CTX* ctx) {
SSL* ssl;
ssl = SSL_new(ctx);
SSL_set_fd(ssl, cli);
DnsData(ssl);
}
This works in terminal mode. Now I need to change terminal mode to GUI mode. GUI mode is web browser. This code uses ssl certificate generated by me. How to write simple ssl dns queried web browser in c?
Ive written the following echo server using UDP but i have no idea that why it is giving me Segmentation Fault in sendto function, it receives fine but has problem sending data back to client. Ive been trying to find the problem for a few hours now but got no where. Can somebody please point out the fault or what i may be doing wrong.
Thanks
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define true 1
#define false 0
int main(int argc,char **args)
{
int BUF_LENGTH=101;
int port_no=1800;
struct sockaddr_in serv_addr,rmt_addr;
//rmt_addr=malloc(sizeof(struct sockaddr_in));
char *buffer=malloc(BUF_LENGTH);
int byte_recv=0;
int rmt_length=0;
int sock_id;
sock_id=socket(AF_INET,SOCK_DGRAM,0);
if(sock_id<0)
{
printf("Error creating socket : %d",sock_id);
return -1;
}
serv_addr.sin_family=AF_INET;
serv_addr.sin_port=htons(port_no);
serv_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
bind(sock_id,(struct sockaddr*)&serv_addr,sizeof(serv_addr));
printf("Created\n");
while(true)
{
printf("Waiting\n");
byte_recv=recvfrom(sock_id,buffer,BUF_LENGTH,0,(struct sockaddr*)&rmt_addr,&rmt_length);
printf("%s\n",buffer);
if(byte_recv<0)
{
printf("Error receiving: %d",byte_recv);
error("recvfrom");
return -2;
}
printf("%d:%d %s\n",rmt_length,rmt_addr.sin_port,inet_ntoa(rmt_addr.sin_addr));
byte_recv=sendto(sock_id,buffer,BUF_LENGTH,0,(struct sockaddr*)&rmt_addr,rmt_length); //The segmentation fault comes here
printf("Bytes sent: %d \n",byte_recv);
if(byte_recv<0)
error("sendto");
}
free(buffer);
return 0;
}
These lines:
error("recvfrom");
error("sendto");
don't do what you think they do. You probably meant to say perror.
Additionally, you aren't initializing rmt_length correctly. Try this:
int rmt_length=sizeof(rmt_addr);
Finally, you are echoing more bytes back than the server receives. Try this:
byte_recv=sendto(sock_id,buffer,byte_recv,0,(struct sockaddr*)&rmt_addr,rmt_length);