- if (sc->t == ':')
- token(sc);
- if (sc->t != CTOK_WORD)
- error(sc, "parse error, destination port expected");
- dp = portnum(sc, sc->d.buf);
-
- /* --- Make the socket --- */
-
- if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
- error(sc, "couldn't create socket: %s", strerror(errno));
-
- /* --- Set it to allow address reuse --- */
-
- {
- int opt = 1;
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
- }
-
- /* --- Bind it to the right port --- */
-
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = htonl(INADDR_ANY);
- sin.sin_port = sp;
- if (bind(fd, (struct sockaddr *)&sin, sizeof(sin))) {
- error(sc, "couldn't bind to port %i: %s",
- ntohs(sp), strerror(errno));
- }
-
- /* --- Set it to listen for connections --- */
-
- if (listen(fd, 5))
- error(sc, "couldn't listen on socket: %s", strerror(errno));