403 |
{ |
{ |
404 |
OPM_SCAN_T *scan; /* New scan for OPM_T */ |
OPM_SCAN_T *scan; /* New scan for OPM_T */ |
405 |
OPM_NODE_T *node; /* Node we'll add scan to when we link it to scans */ |
OPM_NODE_T *node; /* Node we'll add scan to when we link it to scans */ |
406 |
opm_inaddr in; |
struct in_addr in; |
407 |
|
|
408 |
if (LIST_SIZE(scanner->protocols) == 0 && |
if (LIST_SIZE(scanner->protocols) == 0 && |
409 |
LIST_SIZE(remote->protocols) == 0) |
LIST_SIZE(remote->protocols) == 0) |
414 |
* Could have been stuffed into the _OPM_REMOTE struct by the caller that |
* Could have been stuffed into the _OPM_REMOTE struct by the caller that |
415 |
* already does getaddrinfo() anyway. |
* already does getaddrinfo() anyway. |
416 |
*/ |
*/ |
417 |
if (inet_pton(AF_INET, remote->ip, &in.in4) <= 0) |
if (inet_pton(AF_INET, remote->ip, &in) <= 0) |
418 |
return OPM_ERR_BADADDR; |
return OPM_ERR_BADADDR; |
419 |
|
|
420 |
scan = libopm_scan_create(scanner, remote); |
scan = libopm_scan_create(scanner, remote); |
421 |
memcpy(&scan->addr.sa4.sin_addr, &in.in4, sizeof(scan->addr.sa4.sin_addr)); |
memcpy(&scan->addr.sin_addr, &in, sizeof(scan->addr.sin_addr)); |
422 |
|
|
423 |
node = libopm_node_create(scan); |
node = libopm_node_create(scan); |
424 |
libopm_list_add(scanner->queue, node); |
libopm_list_add(scanner->queue, node); |
903 |
static void |
static void |
904 |
libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
905 |
{ |
{ |
906 |
opm_sockaddr *bind_ip; |
struct sockaddr_in *bind_ip; |
907 |
struct sockaddr_in *addr; /* Outgoing host */ |
struct sockaddr_in *addr; /* Outgoing host */ |
908 |
struct sockaddr_in local_addr; /* For binding */ |
struct sockaddr_in local_addr; /* For binding */ |
909 |
|
|
910 |
addr = (struct sockaddr_in *)&(scan->addr.sa4); /* Already have the IP in byte format from opm_scan */ |
addr = &scan->addr; /* Already have the IP in byte format from opm_scan */ |
911 |
addr->sin_family = AF_INET; |
addr->sin_family = AF_INET; |
912 |
addr->sin_port = htons(conn->port); |
addr->sin_port = htons(conn->port); |
913 |
|
|
914 |
bind_ip = (opm_sockaddr *)libopm_config(scanner->config, OPM_CONFIG_BIND_IP); |
bind_ip = (struct sockaddr_in *)libopm_config(scanner->config, OPM_CONFIG_BIND_IP); |
915 |
|
|
916 |
conn->fd = socket(AF_INET, SOCK_STREAM, 0); |
conn->fd = socket(AF_INET, SOCK_STREAM, 0); |
917 |
scanner->fd_use++; /* Increase file descriptor use */ |
scanner->fd_use++; /* Increase file descriptor use */ |
927 |
{ |
{ |
928 |
memset(&local_addr, 0, sizeof(local_addr)); |
memset(&local_addr, 0, sizeof(local_addr)); |
929 |
|
|
930 |
local_addr.sin_addr.s_addr = bind_ip->sa4.sin_addr.s_addr; |
local_addr.sin_addr.s_addr = bind_ip->sin_addr.s_addr; |
931 |
local_addr.sin_family = AF_INET; |
local_addr.sin_family = AF_INET; |
932 |
local_addr.sin_port = htons(0); |
local_addr.sin_port = htons(0); |
933 |
|
|