+ gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
+ gras_procdata_t *pd=(gras_procdata_t *)MSG_process_get_data(MSG_process_self());
+ int port,i;
+ const char *host=MSG_host_get_name(MSG_host_self());
+
+ gras_assert0(hd,"Please run gras_process_init on each process");
+ gras_assert0(pd,"Please run gras_process_init on each process");
+
+ for (port=startingPort ; port <= endingPort ; port++) {
+ for (i=0; i<hd->portLen && hd->port[i] != port; i++);
+ if (i<hd->portLen && hd->port[i] == port)
+ continue;
+
+ /* port not used so far. Do it */
+ if (i == hd->portLen) {
+ /* need to enlarge the tables */
+ if (hd->portLen++) {
+ hd->port2chan=(int*)realloc(hd->port2chan,hd->portLen*sizeof(int));
+ hd->port =(int*)realloc(hd->port ,hd->portLen*sizeof(int));
+ hd->raw =(int*)realloc(hd->raw ,hd->portLen*sizeof(int));
+ } else {
+ hd->port2chan=(int*)malloc(hd->portLen*sizeof(int));
+ hd->port =(int*)malloc(hd->portLen*sizeof(int));
+ hd->raw =(int*)malloc(hd->portLen*sizeof(int));
+ }
+ if (!hd->port2chan || !hd->port || !hd->raw) {
+ fprintf(stderr,"GRAS: PANIC: A malloc error did lose all ports attribution on this host\n");
+ hd->portLen = 0;
+ return malloc_error;
+ }
+ }
+ hd->port2chan[ i ]=raw ? pd->rawChan : pd->chan;
+ hd->port[ i ]=port;
+ hd->raw[ i ]=raw;
+
+ /* Create the socket */
+ if (!(*sock=(gras_sock_t*)malloc(sizeof(gras_sock_t)))) {
+ fprintf(stderr,"GRAS: openServerSocket: out of memory\n");
+ return malloc_error;
+ }
+
+ (*sock)->server_sock = 1;
+ (*sock)->raw_sock = raw;
+ (*sock)->from_PID = -1;
+ (*sock)->to_PID = MSG_process_self_PID();
+ (*sock)->to_host = MSG_host_self();
+ (*sock)->to_port = port;
+ (*sock)->to_chan = pd->chan;
+
+ /*
+ fprintf(stderr,"GRAS: '%s' (%d) ears on %s:%d%s (%p).\n",
+ MSG_process_get_name(MSG_process_self()), MSG_process_self_PID(),
+ host,port,raw? " (mode RAW)":"",*sock);
+ */
+ return no_error;
+ }
+ /* if we go out of the previous for loop, that's that we didn't find any
+ suited port number */