#include "erdm.h"
#include "erdminternal.h"
Go to the source code of this file.
Functions | |
int | dmGetServerPort (int *port) |
int | initServer (int *sockfd, int local) |
int | dmMessageParser (char *szMessage, uDmCommand *dmCommand) |
int dmGetServerPort | ( | int * | port | ) |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition at line 37 of file erdmServer.c.
00038 { 00039 *port = DMPORT; 00040 return 0; 00041 }
int dmMessageParser | ( | char * | szMessage, | |
uDmCommand * | dmCommand | |||
) |
Definition at line 297 of file erdmServer.c.
00298 { 00299 // The real parser.... 00300 erDmCmd_t cmd; 00301 int nRet; 00302 00303 nRet = dmParseMessage(szMessage, &cmd); 00304 if (nRet != 0) 00305 { 00306 ERDM_ERRORPRINTF("dmParseMessage failed with errorcode %d", nRet); 00307 return -1; 00308 } 00309 00310 nRet = dmParseCommand(&cmd, dmCommand); 00311 if (nRet != 0) 00312 { 00313 ERDM_ERRORPRINTF("dmParseCommand failed with errorcode %d", nRet); 00314 return -1; 00315 } 00316 00317 nRet = dmValidateCommand(dmCommand); 00318 if (nRet != 0) 00319 { 00320 ERDM_ERRORPRINTF("dmValidateCommand failed with errorcode %d", nRet); 00321 return -1; 00322 } 00323 return 0; 00324 }
int initServer | ( | int * | sockfd, | |
int | local | |||
) |
Definition at line 47 of file erdmServer.c.
00048 { 00049 int error; 00050 int port; 00051 struct sockaddr_in serverAdr; 00052 00053 *sockfd = socket(AF_INET, SOCK_DGRAM, 0); 00054 dmGetServerPort(&port); 00055 00056 bzero(&serverAdr, sizeof(serverAdr)); 00057 serverAdr.sin_family = AF_INET; 00058 // NOTE : 00059 // Setting the address to INADDR_LOOPBACK will only allow processes running 00060 // on the same host to send messages to the displayMgrServer 00061 // Setting the address to INADDR_ANY will allow a process on any host to 00062 // send messages to the displayMgrServer 00063 if (local == 1) 00064 { 00065 serverAdr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 00066 } 00067 else 00068 { 00069 serverAdr.sin_addr.s_addr = htonl(INADDR_ANY); 00070 } 00071 serverAdr.sin_port = htons(port); 00072 00073 error = bind(*sockfd, (struct sockaddr *) &serverAdr, sizeof(serverAdr)); 00074 if (error) 00075 { 00076 perror("Error invoking bind"); 00077 return -1; 00078 } 00079 else 00080 { 00081 char szServerIP[INET_ADDRSTRLEN + 1]; 00082 00083 inet_ntop(AF_INET, &serverAdr.sin_addr, szServerIP, sizeof(szServerIP)); 00084 ERDM_WARNPRINTF("Bound successfully to %s:%d.", szServerIP, port); 00085 } 00086 return 0; 00087 }