struct tcpconn {
struct sockaddr_storage name;
struct tcpport *port;
+ int fd;
};
-static int listensock4(int port)
+int listensock4(int port)
{
struct sockaddr_in name;
int fd;
return(fd);
}
-static int listensock6(int port)
+int listensock6(int port)
{
struct sockaddr_in6 name;
int fd;
static int initreq(struct conn *conn, struct hthead *req)
{
struct tcpconn *tcp = conn->pdata;
+ struct sockaddr_storage sa;
+ socklen_t salen;
char nmbuf[256];
if(tcp->name.ss_family == AF_INET) {
headappheader(req, "X-Ash-Address", inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&tcp->name)->sin6_addr, nmbuf, sizeof(nmbuf)));
headappheader(req, "X-Ash-Port", sprintf3("%i", ntohs(((struct sockaddr_in6 *)&tcp->name)->sin6_port)));
}
+ salen = sizeof(sa);
+ if(!getsockname(tcp->fd, (struct sockaddr *)&sa, &salen)) {
+ if(sa.ss_family == AF_INET)
+ headappheader(req, "X-Ash-Server-Address", inet_ntop(AF_INET, &((struct sockaddr_in *)&sa)->sin_addr, nmbuf, sizeof(nmbuf)));
+ else if(sa.ss_family == AF_INET6)
+ headappheader(req, "X-Ash-Server-Address", inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&sa)->sin6_addr, nmbuf, sizeof(nmbuf)));
+ }
headappheader(req, "X-Ash-Server-Port", sprintf3("%i", tcp->port->sport));
headappheader(req, "X-Ash-Protocol", "http");
return(0);
in = mtstdopen(fd, 1, 60, "r+");
conn.pdata = &tcp;
conn.initreq = initreq;
+ tcp.fd = fd;
tcp.name = name;
tcp.port = stcp;
serve(in, &conn);
for(i = 0; i < argc; i++) {
if(!strcmp(argp[i], "help")) {
printf("plain handler parameters:\n");
- printf("\tport=TCP-PORT (default is 80)\n");
+ printf("\tport=TCP-PORT [80]\n");
+ printf("\t\tThe TCP port to listen on.\n");
exit(0);
} else if(!strcmp(argp[i], "port")) {
port = atoi(argv[i]);