version 1.1.1.1, 2012/02/21 16:42:02
|
version 1.1.1.3, 2013/07/21 23:49:22
|
Line 1
|
Line 1
|
/* |
/* |
* Copyright (C) 2008-2010 Daisuke Aoyama <aoyama@peach.ne.jp>. | * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>. |
* All rights reserved. |
* All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
Line 41
|
Line 41
|
#include <netinet/tcp.h> |
#include <netinet/tcp.h> |
|
|
#include "istgt.h" |
#include "istgt.h" |
|
#include "istgt_log.h" |
#include "istgt_sock.h" |
#include "istgt_sock.h" |
#include "istgt_misc.h" |
#include "istgt_misc.h" |
|
|
Line 54
|
Line 55
|
#define AI_NUMERICSERV 0 |
#define AI_NUMERICSERV 0 |
#endif |
#endif |
|
|
|
#if !defined(__GNUC__) |
|
#undef __attribute__ |
|
#define __attribute__(x) |
|
#endif |
|
|
int |
int |
istgt_getaddr(int sock, char *saddr, int slen, char *caddr, int clen) |
istgt_getaddr(int sock, char *saddr, int slen, char *caddr, int clen) |
{ |
{ |
Line 65 istgt_getaddr(int sock, char *saddr, int slen, char *c
|
Line 71 istgt_getaddr(int sock, char *saddr, int slen, char *c
|
salen = sizeof sa; |
salen = sizeof sa; |
rc = getsockname(sock, (struct sockaddr *) &sa, &salen); |
rc = getsockname(sock, (struct sockaddr *) &sa, &salen); |
if (rc != 0) { |
if (rc != 0) { |
|
ISTGT_ERRLOG("getsockname() failed (errno=%d)\n", errno); |
return -1; |
return -1; |
} |
} |
rc = getnameinfo((struct sockaddr *) &sa, salen, |
rc = getnameinfo((struct sockaddr *) &sa, salen, |
saddr, slen, NULL, 0, NI_NUMERICHOST); | saddr, slen, NULL, 0, NI_NUMERICHOST); |
if (rc != 0) { |
if (rc != 0) { |
|
ISTGT_ERRLOG("getnameinfo() failed (errno=%d)\n", errno); |
return -1; |
return -1; |
} |
} |
|
|
Line 77 istgt_getaddr(int sock, char *saddr, int slen, char *c
|
Line 85 istgt_getaddr(int sock, char *saddr, int slen, char *c
|
salen = sizeof sa; |
salen = sizeof sa; |
rc = getpeername(sock, (struct sockaddr *) &sa, &salen); |
rc = getpeername(sock, (struct sockaddr *) &sa, &salen); |
if (rc != 0) { |
if (rc != 0) { |
|
ISTGT_ERRLOG("getpeername() failed (errno=%d)\n", errno); |
return -1; |
return -1; |
} |
} |
rc = getnameinfo((struct sockaddr *) &sa, salen, |
rc = getnameinfo((struct sockaddr *) &sa, salen, |
caddr, clen, NULL, 0, NI_NUMERICHOST); | caddr, clen, NULL, 0, NI_NUMERICHOST); |
if (rc != 0) { |
if (rc != 0) { |
|
ISTGT_ERRLOG("getnameinfo() failed (errno=%d)\n", errno); |
return -1; |
return -1; |
} |
} |
|
|
Line 126 istgt_listen(const char *ip, int port)
|
Line 136 istgt_listen(const char *ip, int port)
|
hints.ai_flags |= AI_NUMERICHOST; |
hints.ai_flags |= AI_NUMERICHOST; |
rc = getaddrinfo(ip, portnum, &hints, &res0); |
rc = getaddrinfo(ip, portnum, &hints, &res0); |
if (rc != 0) { |
if (rc != 0) { |
|
ISTGT_ERRLOG("getaddrinfo() failed (errno=%d)\n", errno); |
return -1; |
return -1; |
} |
} |
|
|
Line 214 istgt_connect(const char *host, int port)
|
Line 225 istgt_connect(const char *host, int port)
|
hints.ai_flags = AI_NUMERICSERV; |
hints.ai_flags = AI_NUMERICSERV; |
rc = getaddrinfo(host, portnum, &hints, &res0); |
rc = getaddrinfo(host, portnum, &hints, &res0); |
if (rc != 0) { |
if (rc != 0) { |
|
ISTGT_ERRLOG("getaddrinfo() failed (errno=%d)\n", errno); |
return -1; |
return -1; |
} |
} |
|
|
Line 285 istgt_set_sendtimeout(int s, int msec)
|
Line 297 istgt_set_sendtimeout(int s, int msec)
|
return 0; |
return 0; |
} |
} |
|
|
|
int |
|
istgt_set_recvlowat(int s, int nbytes) |
|
{ |
|
int val; |
|
int rc; |
|
|
|
val = nbytes; |
|
rc = setsockopt(s, SOL_SOCKET, SO_RCVLOWAT, &val, sizeof val); |
|
if (rc != 0) |
|
return -1; |
|
return 0; |
|
} |
|
|
#ifdef USE_POLLWAIT |
#ifdef USE_POLLWAIT |
static int |
static int |
can_read_socket(int s, int msec) |
can_read_socket(int s, int msec) |
Line 339 can_write_socket(int s, int msec)
|
Line 364 can_write_socket(int s, int msec)
|
} |
} |
#endif /* USE_POLLWAIT */ |
#endif /* USE_POLLWAIT */ |
|
|
|
#ifdef USE_POLLWAIT |
|
#define UNUSED_POLLWAIT(x) x |
|
#else |
|
#define UNUSED_POLLWAIT(x) x __attribute__((__unused__)) |
|
#endif |
|
|
ssize_t |
ssize_t |
istgt_read_socket(int s, void *buf, size_t nbytes, int timeout) | istgt_read_socket(int s, void *buf, size_t nbytes, int UNUSED_POLLWAIT(timeout)) |
{ |
{ |
ssize_t n; |
ssize_t n; |
#ifdef USE_POLLWAIT |
#ifdef USE_POLLWAIT |
Line 387 istgt_read_socket(int s, void *buf, size_t nbytes, int
|
Line 418 istgt_read_socket(int s, void *buf, size_t nbytes, int
|
} |
} |
|
|
ssize_t |
ssize_t |
istgt_write_socket(int s, const void *buf, size_t nbytes, int timeout) | istgt_write_socket(int s, const void *buf, size_t nbytes, int UNUSED_POLLWAIT(timeout)) |
{ |
{ |
ssize_t n; |
ssize_t n; |
#ifdef USE_POLLWAIT |
#ifdef USE_POLLWAIT |