Browse Source

add code to get the ip address from a socket.

1.0.0
Georg Hopp 12 years ago
parent
commit
2b98364674
  1. 10
      include/tr/socket.h
  2. 2
      src/Makefile.am
  3. 35
      src/get_ip.c
  4. 35
      src/get_ip_str.c
  5. 4
      trio.h

10
include/tr/socket.h

@ -37,10 +37,12 @@ TR_CLASS(TR_Sock) {
int handle;
};
void TR_socketConnect(TR_Sock this, const char * addr, char (*)[16]);
void TR_socketListen(TR_Sock this, int backlog);
TR_Sock TR_socketAccept(TR_Sock this, char (*remoteAddr)[16]);
void TR_socketNonblock(TR_Sock this);
void TR_socketConnect(TR_Sock this, const char * addr, char (*)[16]);
void TR_socketListen(TR_Sock this, int backlog);
TR_Sock TR_socketAccept(TR_Sock this, char (*remoteAddr)[16]);
void TR_socketNonblock(TR_Sock this);
in_addr_t TR_socketGetIp(TR_Sock this);
const char * const TR_socketGetIpStr(TR_Sock this);
#endif // __TR_SOCKET_H__

2
src/Makefile.am

@ -10,6 +10,8 @@ TRIO = stream.c \
accept.c \
connect.c \
listen.c \
get_ip.c \
get_ip_str.c \
nonblock.c \
i_reader.c \
i_writer.c

35
src/get_ip.c

@ -0,0 +1,35 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <arpa/inet.h>
#include "trbase.h"
#include "tr/socket.h"
#include "tr/logger.h"
in_addr_t
TR_socketGetIp(TR_Sock this)
{
return this->addr.sin_addr.s_addr;
}
// vim: set ts=4 sw=4:

35
src/get_ip_str.c

@ -0,0 +1,35 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <arpa/inet.h>
#include "trbase.h"
#include "tr/socket.h"
#include "tr/logger.h"
const char * const
TR_socketGetIpStr(TR_Sock this)
{
return inet_ntoa(this->addr.sin_addr);
}
// vim: set ts=4 sw=4:

4
trio.h

@ -11,13 +11,13 @@
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* #undef HAVE_MEMSET */
/* Define to 1 if you have the <stdarg.h> header file. */
#define HAVE_STDARG_H 1
/* Define to 1 if stdbool.h conforms to C99. */
#define HAVE_STDBOOL_H 1
/* #undef HAVE_STDBOOL_H */
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

Loading…
Cancel
Save