diff options
-rw-r--r-- | cacheserver/utmpserver.c | 12 | ||||
-rw-r--r-- | include/proto.h | 2 | ||||
-rw-r--r-- | mbbsd/stuff.c | 7 |
3 files changed, 14 insertions, 7 deletions
diff --git a/cacheserver/utmpserver.c b/cacheserver/utmpserver.c index 82832b8f..94c6c0f1 100644 --- a/cacheserver/utmpserver.c +++ b/cacheserver/utmpserver.c @@ -73,20 +73,24 @@ int main(int argc, char **argv) { struct sockaddr_in clientaddr; int ch, port = 5120, sfd, cfd, len, index, i, uid; + char iface_ip[16] = {NULL}; - while( (ch = getopt(argc, argv, "p:h")) != -1 ) + while( (ch = getopt(argc, argv, "p:i:h")) != -1 ) switch( ch ){ case 'p': port = atoi(optarg); break; - + case 'i': + host = strncpy(iface_ip, optarg, 16); + host[15] = 0; + break; case 'h': default: - fprintf(stderr, "usage: utmpserver [-p port]\n"); + fprintf(stderr, "usage: utmpserver [-i interface_ip] [-p port]\n"); return 1; } - if( (sfd = tobind(port)) < 0 ) + if( (sfd = tobind(iface_ip, port)) < 0 ) return 1; while( 1 ){ diff --git a/include/proto.h b/include/proto.h index a6b9104d..771151c5 100644 --- a/include/proto.h +++ b/include/proto.h @@ -595,7 +595,7 @@ int qsort_intcompar(const void *a, const void *b); void FREE(void *ptr); #endif #ifdef OUTTACACHE -int tobind(int port); +int tobind(char *iface_ip, int port); int toconnect(char *host, int port); int toread(int fd, void *buf, int len); int towrite(int fd, void *buf, int len); diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 3e44efdf..ba3253bf 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -955,7 +955,7 @@ time4_t time4(time4_t *ptr) #endif #ifdef OUTTACACHE -int tobind(int port) +int tobind(char * host, int port) { int sockfd, val; struct sockaddr_in servaddr; @@ -968,7 +968,10 @@ int tobind(int port) (char *)&val, sizeof(val)); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + if (!host || host[0] == NULL) + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + else if (inet_aton(host, &servaddr.sin_addr) == 0) + err(1, NULL); servaddr.sin_port = htons(port); if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) { perror("bind()"); |