25 #include "IPvXAddress.h"
26 #include <regmacros.h>
52 struct sockaddr_in server;
56 sock = socket(AF_INET, SOCK_STREAM, 0);
58 if (sock == INVALID_SOCKET) {
59 opp_error(
"Error creating socket");
64 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&on,
sizeof(on));
66 memset(&server, 0,
sizeof (server));
67 server.sin_family = AF_INET;
68 server.sin_addr.s_addr = htonl(INADDR_ANY);
69 server.sin_port = htons(appPort);
71 if (bind( sock, (
struct sockaddr*)&server,
sizeof( server)) < 0) {
72 opp_error(
"Error binding to app socket");
76 if (listen( sock, 5 ) == -1) {
77 opp_error(
"Error listening on app socket");
90 if (
netw_fd != INVALID_SOCKET) {
102 netw_fd = socket(AF_INET, SOCK_DGRAM, 0);
103 memset(&addr, 0,
sizeof(addr));
104 addr.sin_family = AF_INET;
106 cModule* overlay = simulation.getModuleByPath(
107 "SingleHostUnderlayNetwork.overlayTerminal[0].overlay");
109 if (overlay == NULL) {
110 throw cRuntimeError(
"UdpOutScheduler::initializeNetwork(): "
111 "Overlay module not found!");
114 addr.sin_port = htons(overlay->gate(
"appIn")->getNextGate()->
115 getOwnerModule()->par(
"localPort").longValue());
117 cModule* underlayConfigurator =
118 simulation.getModuleByPath(
"SingleHostUnderlayNetwork.underlayConfigurator");
120 if (underlayConfigurator == NULL) {
121 throw cRuntimeError(
"UdpOutScheduler::initializeNetwork(): "
122 "UnderlayConfigurator module not found!");
125 if (strlen(underlayConfigurator->par(
"nodeIP").stringValue())) {
126 addr.sin_addr.s_addr = htonl(IPAddress(underlayConfigurator->
127 par(
"nodeIP").stringValue()).getInt());
129 addr.sin_addr.s_addr = htonl(INADDR_ANY);
132 if (bind(
netw_fd, (sockaddr*)&addr,
sizeof(addr)) < 0) {
133 opp_error(
"Error binding to UDP socket");
147 sockaddr* from = (sockaddr*)
new sockaddr_in;
148 socklen_t addrlen =
sizeof(sockaddr_in);
152 if (new_sock == INVALID_SOCKET) {
153 opp_warning(
"Error connecting to remote app");
160 for (SOCKET fd = 0; fd <=
maxfd; fd++) {
163 if (FD_ISSET(fd, &
all_fds)) count++;
170 closesocket(new_sock);
174 ev <<
"[UdpOutScheduler::additionalFD()]\n"
175 <<
" Rejecting new app connection (FD: " << new_sock <<
")"
184 if (new_sock >
maxfd) {
194 ev <<
"[UdpOutScheduler::additionalFD()]\n"
195 <<
" Accepting new app connection (FD: " << new_sock <<
")"