113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
-
-
-
+
+
+
+
+
-
-
+
+
+
-
+
|
if (!port)
@throw [OFInvalidPortException newWithObject: self];
if (sock >= 0)
@throw [OFAlreadyConnectedException newWithObject: self];
if ((sock = socket(family, SOCK_STREAM, 0)) < 0) {
/* FIXME: Throw exception */
return nil;
if ((sock = socket(family, SOCK_STREAM, 0)) < 0)
@throw [OFBindFailedException newWithObject: self
andHost: host
andPort: port
andFamily: family];
}
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
snprintf(portstr, 6, "%d", port);
if (getaddrinfo(host, portstr, &hints, &res))
@throw [OFAddressTranslationFailedException
newWithObject: self
andNode: host
andService: portstr];
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
/* FIXME: Throw exception */
freeaddrinfo(res);
@throw [OFBindFailedException newWithObject: self
andHost: host
andPort: port
return nil;
andFamily: family];
}
freeaddrinfo(res);
return self;
}
|