char * honeyd_contoa(const struct tuple *hdr) { static char buf[128]; char asrc[24], adst[24]; struct addr src, dst; u_short sport, dport; addr_pack(&src, ADDR_TYPE_IP, IP_ADDR_BITS, &hdr->ip_src, IP_ADDR_LEN); addr_pack(&dst, ADDR_TYPE_IP, IP_ADDR_BITS, &hdr->ip_dst, IP_ADDR_LEN); /* For a local connection switch the address around */ if (hdr->local) { struct addr tmp; tmp = src; src = dst; dst = tmp; sport = hdr->dport; dport = hdr->sport; } else { sport = hdr->sport; dport = hdr->dport; } addr_ntop(&src, asrc, sizeof(asrc)); addr_ntop(&dst, adst, sizeof(adst)); snprintf(buf, sizeof(buf), "(%s:%d - %s:%d)", asrc, sport, adst, dport); return (buf); }
void open_devices(void) { i = intf_open(); if ( i == NULL ) { perror("intf open error"); exit(-1); } strncpy(ie.intf_name, iface, 60); if ( intf_get(i, &ie) == -1 ) { perror("intf get error"); exit(-1); } mha = ie.intf_link_addr; if ( addr_ntop(&mha, mhw, 32) == NULL ){ exit(-1); } mad = ie.intf_addr; if ( addr_ntop(&mad, mip, 32) == NULL ){ exit(-1); } rmslash(mip); e = eth_open(iface); if ( e == NULL ) { perror("eth open error"); exit(-1); } p = pcap_open_live(iface, 20000, 1, 500, ebuf); if ( p == NULL ) { perror(ebuf); exit(-1); } }
int subsystem_socket(struct subsystem_command *cmd, int local, char *ip, size_t iplen, u_short *port, int *proto) { struct sockaddr_in *si; struct addr src; socklen_t len; si = (struct sockaddr_in *)(local ? &cmd->sockaddr : &cmd->rsockaddr); len = local ? cmd->len : cmd->rlen; /* Only IPv4 TCP or UDP is allowed. No raw sockets or such */ if (si->sin_family != AF_INET || cmd->domain != AF_INET || !(cmd->type == SOCK_DGRAM || cmd->type == SOCK_STREAM) || len != sizeof(struct sockaddr_in)) { if (local == SOCKET_LOCAL) return (-1); memset(&cmd->sockaddr, 0, sizeof(cmd->sockaddr)); } addr_pack(&src, ADDR_TYPE_IP, IP_ADDR_BITS, &si->sin_addr.s_addr, IP_ADDR_LEN); addr_ntop(&src, ip, iplen); *port = ntohs(si->sin_port); *proto = cmd->type == SOCK_DGRAM ? IP_PROTO_UDP : IP_PROTO_TCP; return (0); }
const char* addr_ntop_buf(const struct xaddr* a) { static char hbuf[64]; if (addr_ntop(a, hbuf, sizeof(hbuf)) == -1) return NULL; return (hbuf); }
char * addr_ntoa(const struct addr *a) { static char *p, buf[BUFSIZ]; char *q = NULL; if (p == NULL || p > buf + sizeof(buf) - 64 /* XXX */) p = buf; if (addr_ntop(a, p, (buf + sizeof(buf)) - p) != NULL) { q = p; p += strlen(p) + 1; } return (q); }
/* This function only populates the first (primary) IP * address for an interface. We can extend this to include * aliases later if necessary. */ static int interfaces_callback(const struct intf_entry *entry, void *arg) { PyObject *dict = (PyObject*) arg; char * name; char ip[64]; int rc; /* Interface must be up */ if (! (entry->intf_flags & INTF_FLAG_UP) ) return 0; name = (char*) entry->intf_name; addr_ntop((const struct addr*) &entry->intf_addr, (char*) ip, (size_t) 64); if (!ip) Myerror("Could not find IP address for interface"); rc = PyDict_SetItemString(dict, name, PyString_FromString(ip)); if (rc<0) Myerror("adding to dictionary didn't work"); /* printf("Adding interface %s: %s\n", name, ip); */ return 0; }