73 struct lifreq *reqs = NULL; |
73 struct lifreq *reqs = NULL; |
74 struct lifconf ifconf; |
74 struct lifconf ifconf; |
75 adr_data_t *result; |
75 adr_data_t *result; |
76 |
76 |
77 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) |
77 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) |
78 return (ce_object); |
78 return (CE_OBJECT); |
79 |
79 |
80 do { |
80 do { |
81 if (reqs != NULL) |
81 if (reqs != NULL) |
82 free(reqs); |
82 free(reqs); |
83 |
83 |
84 if (if_count(fd, &count) == -1) |
84 if (if_count(fd, &count) == -1) |
85 return (ce_object); |
85 return (CE_OBJECT); |
86 |
86 |
87 if (count == 0) { |
87 if (count == 0) { |
88 (void) close(fd); |
88 (void) close(fd); |
89 *data = adr_data_new_array(&adr_t_array_string, 0); |
89 *data = adr_data_new_array(&adr_t_array_string, 0); |
90 return (ce_ok); |
90 return (CE_OK); |
91 } |
91 } |
92 |
92 |
93 count += 5; |
93 count += 5; |
94 reqsize = count * sizeof (struct lifreq); |
94 reqsize = count * sizeof (struct lifreq); |
95 if ((reqs = malloc(reqsize)) == NULL) { |
95 if ((reqs = malloc(reqsize)) == NULL) { |
96 (void) close(fd); |
96 (void) close(fd); |
97 return (ce_object); |
97 return (CE_OBJECT); |
98 } |
98 } |
99 |
99 |
100 ifconf.lifc_family = AF_INET; |
100 ifconf.lifc_family = AF_INET; |
101 ifconf.lifc_len = reqsize; |
101 ifconf.lifc_len = reqsize; |
102 ifconf.lifc_buf = (char *)reqs; |
102 ifconf.lifc_buf = (char *)reqs; |
103 ifconf.lifc_flags = 0; |
103 ifconf.lifc_flags = 0; |
104 if (ioctl(fd, SIOCGLIFCONF, &ifconf) == -1) { |
104 if (ioctl(fd, SIOCGLIFCONF, &ifconf) == -1) { |
105 (void) close(fd); |
105 (void) close(fd); |
106 free(reqs); |
106 free(reqs); |
107 return (ce_object); |
107 return (CE_OBJECT); |
108 } |
108 } |
109 rcount = ifconf.lifc_len / sizeof (struct lifreq); |
109 rcount = ifconf.lifc_len / sizeof (struct lifreq); |
110 } while (rcount >= count); |
110 } while (rcount >= count); |
111 |
111 |
112 result = adr_data_new_array(&adr_t_array_string, rcount); |
112 result = adr_data_new_array(&adr_t_array_string, rcount); |
137 int errnum; |
137 int errnum; |
138 struct hostent *he; |
138 struct hostent *he; |
139 ipaddr_t addr; |
139 ipaddr_t addr; |
140 |
140 |
141 if (inet_pton(AF_INET, adr_data_to_string(args[0]), &addr) != 1) |
141 if (inet_pton(AF_INET, adr_data_to_string(args[0]), &addr) != 1) |
142 return (ce_object); |
142 return (CE_OBJECT); |
143 |
143 |
144 if ((he = getipnodebyaddr(&addr, sizeof (addr), AF_INET, &errnum)) |
144 if ((he = getipnodebyaddr(&addr, sizeof (addr), AF_INET, &errnum)) |
145 == NULL) { |
145 == NULL) { |
146 /* Not found? Bounce it back. */ |
146 /* Not found? Bounce it back. */ |
147 (void) adr_data_ref(args[0]); |
147 (void) adr_data_ref(args[0]); |
148 *ret = args[0]; |
148 *ret = args[0]; |
149 return (ce_ok); |
149 return (CE_OK); |
150 } |
150 } |
151 |
151 |
152 adr_data_t *result = adr_data_new_string(he->h_name, LT_COPY); |
152 adr_data_t *result = adr_data_new_string(he->h_name, LT_COPY); |
153 freehostent(he); |
153 freehostent(he); |
154 *ret = result; |
154 *ret = result; |
155 |
155 |
156 return (ce_ok); |
156 return (CE_OK); |
157 } |
157 } |
158 |
158 |
159 /* ARGSUSED */ |
159 /* ARGSUSED */ |
160 conerr_t |
160 conerr_t |
161 interface_Network_invoke_hostGetIPs(rad_instance_t *inst, adr_method_t *meth, |
161 interface_Network_invoke_hostGetIPs(rad_instance_t *inst, adr_method_t *meth, |
214 // lo0 127.0.0.1 (AF_INET) |
214 // lo0 127.0.0.1 (AF_INET) |
215 // e1000g0 129.XXX.XXX.XXX (AF_INET) |
215 // e1000g0 129.XXX.XXX.XXX (AF_INET) |
216 // |
216 // |
217 // See: man -s3 socket getifaddrs |
217 // See: man -s3 socket getifaddrs |
218 if (getifaddrs(&ifaddr) == -1) { |
218 if (getifaddrs(&ifaddr) == -1) { |
219 return (ce_object); |
219 return (CE_OBJECT); |
220 } |
220 } |
221 |
221 |
222 /* Iterate over linked list of IP addresses */ |
222 /* Iterate over linked list of IP addresses */ |
223 for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { |
223 for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { |
224 if (ifa->ifa_flags & IFF_IPV4) { |
224 if (ifa->ifa_flags & IFF_IPV4) { |
244 break; |
244 break; |
245 } |
245 } |
246 } |
246 } |
247 } |
247 } |
248 freeifaddrs(ifaddr); |
248 freeifaddrs(ifaddr); |
249 return (ce_ok); |
249 return (CE_OK); |
250 } |
250 } |
251 |
|
252 static rad_modinfo_t modinfo = { "network", "Network panel support" }; |
|
253 |
251 |
254 int |
252 int |
255 _rad_init(void *handle) |
253 _rad_init(void) |
256 { |
254 { |
257 if (rad_module_register(handle, RAD_MODVERSION, &modinfo) == -1) |
255 adr_name_t *aname = adr_name_vcreate(MOD_DOMAIN, 1, "type", "Network"); |
|
256 conerr_t cerr = rad_cont_insert_singleton(rad_container, aname, |
|
257 &modinfo, &interface_Network_svr); |
|
258 adr_name_rele(aname); |
|
259 if (cerr != CE_OK) { |
|
260 rad_log(RL_ERROR, "(mod_network) failed to insert Network"); |
258 return (-1); |
261 return (-1); |
259 |
262 } |
260 if (rad_isproxy) |
|
261 return (0); |
|
262 |
|
263 (void) cont_insert_singleton(rad_container, adr_name_fromstr( |
|
264 "com.oracle.solaris.vp.panel.common.api.network:type=Network"), |
|
265 &interface_Network_svr); |
|
266 |
263 |
267 return (0); |
264 return (0); |
268 } |
265 } |
|
266 |
|
267 /* |
|
268 * _rad_fini is called by the RAD daemon when the module is unloaded. Any |
|
269 * module finalisation is completed here. |
|
270 */ |
|
271 /*ARGSUSED*/ |
|
272 void |
|
273 _rad_fini(void *unused) |
|
274 { |
|
275 } |