python27: use absolute path to dtrace(8)
[unleashed-userland.git] / components / python / python27 / patches / 07-dlpi.patch
blob3f7901938acc11d7c3dbf10ec3d5c06d080fe9ba
1 This patch provides Python dlpi support.
3 diff --git Python-2.6.4/Modules/dlpimodule.c Python-2.6.4/Modules/dlpimodule.c
4 new file mode 100644
5 --- /dev/null
6 +++ Python-2.6.4/Modules/dlpimodule.c
7 @@ -0,0 +1,1205 @@
8 +/*
9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
10 + * of this software and associated documentation files (the "Software"), to
11 + * deal in the Software without restriction, including without limitation the
12 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13 + * sell copies of the Software, and to permit persons to whom the Software is
14 + * furnished to do so, subject to the following conditions:
15 + *
16 + * The above copyright notice and this permission notice shall be included in
17 + * all copies or substantial portions of the Software.
18 + *
19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 + * DEALINGS IN THE SOFTWARE.
26 + *
27 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
28 + */
30 +#include <Python.h>
31 +#include <stdio.h>
32 +#include <libdlpi.h>
34 +typedef struct {
35 + PyObject_HEAD
36 + dlpi_handle_t dlpihdl;
37 +} pylink_t;
39 +typedef struct {
40 + PyObject *pyfunc;
41 + PyObject *pyarg;
42 +} callback_data_t;
44 +/*
45 + * dlpi_err: the only exception raised for libdlpi related error.
46 + * The accompanying value is:
47 + * (dlpi_error_number, string), when it's a dlpi specific error,
48 + * or, (DL_SYSERR, errno, string), when it's coming from a system call.
49 + */
50 +static PyObject *dlpi_err;
52 +static void
53 +dlpi_raise_exception(int err)
55 + PyObject *e = NULL;
57 + if (err == DL_SYSERR) {
58 + e = Py_BuildValue("(iis)", DL_SYSERR, errno, strerror(errno));
59 + } else {
60 + e = Py_BuildValue("(is)", err, dlpi_strerror(err));
61 + }
62 + if (e != NULL) {
63 + PyErr_SetObject(dlpi_err, e);
64 + Py_DECREF(e);
65 + }
68 +PyDoc_STRVAR(link_doc,
69 + "link(linkname[, flags]) -> link object\n"
70 + "\n"
71 + "Open linkname with specified flags.\n"
72 + "Three flags are supported: PASSIVE, RAW, NATIVE.\n"
73 + "And these flags can be bitwise-OR'ed together(default flag is 0).\n"
74 + "You need sys_net_rawaccess privilege to open a link.\n"
75 + "See dlpi_open(3DLPI).\n"
76 +);
77 +static int
78 +link_init(PyObject *self, PyObject *args, PyObject *kwds)
80 + uint_t flags = 0;
81 + dlpi_handle_t dh;
82 + char *linkname;
83 + int rval;
84 + static char *keywords[] = {"linkname", "flags", NULL};
85 + pylink_t *link = (pylink_t *)self;
87 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|I", keywords,
88 + &linkname, &flags))
89 + return (-1);
91 + if ((rval = dlpi_open(linkname, &dh, flags)) != DLPI_SUCCESS) {
92 + dlpi_raise_exception(rval);
93 + return (-1);
94 + }
96 + link->dlpihdl = dh;
98 + return (0);
101 +static void
102 +link_dealloc(pylink_t *link)
104 + if (link->dlpihdl != NULL)
105 + dlpi_close(link->dlpihdl);
106 + link->ob_type->tp_free((PyObject *)link);
109 +PyDoc_STRVAR(bind_doc,
110 + "bind(sap) -> unsigned int\n"
111 + "\n"
112 + "Attempts to bind the link to specified SAP, or ANY_SAP.\n"
113 + "Returns the SAP that the function actually bound to, which\n"
114 + "could be different from the SAP requested.\n"
115 + "See dlpi_bind(3DLPI).\n"
117 +static PyObject *
118 +link_bind(pylink_t *link, PyObject *args, PyObject *kwds)
120 + uint_t sap = 0, boundsap = 0;
121 + static char *keywords[] = {"sap", NULL};
122 + int rval;
124 + if (link->dlpihdl == NULL) {
125 + errno = EINVAL;
126 + dlpi_raise_exception(DL_SYSERR);
127 + return (NULL);
130 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &sap))
131 + return (NULL);
133 + if ((rval = dlpi_bind(link->dlpihdl, sap, &boundsap)) !=
134 + DLPI_SUCCESS) {
135 + dlpi_raise_exception(rval);
136 + return (NULL);
139 + return (Py_BuildValue("I", boundsap));
142 +PyDoc_STRVAR(unbind_doc,
143 + "unbind() -> None\n"
144 + "\n"
145 + "Attempts to unbind the link from previously bound sap.\n"
146 + "See dlpi_unbind(3DLPI).\n"
148 +static PyObject *
149 +link_unbind(pylink_t *link)
151 + int rval;
153 + if (link->dlpihdl == NULL) {
154 + errno = EINVAL;
155 + dlpi_raise_exception(DL_SYSERR);
156 + return (NULL);
159 + if ((rval = dlpi_unbind(link->dlpihdl)) != DLPI_SUCCESS) {
160 + dlpi_raise_exception(rval);
161 + return (NULL);
164 + Py_INCREF(Py_None);
165 + return (Py_None);
168 +PyDoc_STRVAR(send_doc,
169 + "send(destaddr, message[, sap, minpri, maxpri]) -> None\n"
170 + "\n"
171 + "Attempts to send message over this link to sap on destaddr.\n"
172 + "If SAP is not specified, the bound SAP is used\n"
173 + "You can also specify priority range (minpri, maxpri).\n"
174 + "See dlpi_send(3DLPI).\n"
176 +static PyObject *
177 +link_send(pylink_t *link, PyObject *args, PyObject *kwds)
179 + char *daddr = NULL, *msgbuf = NULL;
180 + size_t daddrlen = 0, msglen = 0;
181 + t_scalar_t minpri = DL_QOS_DONT_CARE, maxpri = DL_QOS_DONT_CARE;
182 + uint_t sap = DLPI_ANY_SAP;
183 + dlpi_sendinfo_t ds, *dsp = NULL;
184 + static char *keywords[] =
185 + {"destaddr", "message", "sap", "minpri", "maxpri", NULL};
186 + int rval;
188 + if (link->dlpihdl == NULL) {
189 + errno = EINVAL;
190 + dlpi_raise_exception(DL_SYSERR);
191 + return (NULL);
194 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#s#|Iii", keywords,
195 + &daddr, &daddrlen, &msgbuf, &msglen, &sap, &minpri, &maxpri))
196 + return (NULL);
198 + if ((sap != DLPI_ANY_SAP) || (minpri != DL_QOS_DONT_CARE) ||
199 + (maxpri != DL_QOS_DONT_CARE)) {
200 + ds.dsi_sap = sap;
201 + ds.dsi_prio.dl_min = minpri;
202 + ds.dsi_prio.dl_max = maxpri;
203 + dsp = &ds;
206 + if ((rval = dlpi_send(link->dlpihdl, daddr, daddrlen,
207 + msgbuf, msglen, dsp)) != DLPI_SUCCESS) {
208 + dlpi_raise_exception(rval);
209 + return (NULL);
212 + Py_INCREF(Py_None);
213 + return (Py_None);
216 +PyDoc_STRVAR(recv_doc,
217 + "recv(msglen[, timeout]) -> (string, string), or (None, None)\n"
218 + "\n"
219 + "Attempts to receive message over this link.\n"
220 + "You need to specify the message length for the received message.\n"
221 + "And you can specify timeout value in milliseconds.\n"
222 + "The default timeout value is -1 (wait forever).\n"
223 + "Returns (source address, message data), or (None, None) when error occurs.\n"
224 + "See dlpi_recv(3DLPI).\n"
226 +static PyObject *
227 +link_recv(pylink_t *link, PyObject *args, PyObject *kwds)
229 + PyObject *obj;
230 + char *saddr = NULL, *msgbuf = NULL;
231 + size_t saddrlen = 0, msglen = 0, *saddrlenp = NULL, *msglenp = NULL;
232 + int msec = -1; /* block until receive data */
233 + static char *keywords[] = {"msglen", "timeout", NULL};
234 + int rval;
236 + if (link->dlpihdl == NULL) {
237 + errno = EINVAL;
238 + dlpi_raise_exception(DL_SYSERR);
239 + return (NULL);
242 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "k|i",
243 + keywords, &msglen, &msec))
244 + return (NULL);
246 + if (msglen > 0) {
247 + msgbuf = malloc(msglen);
248 + if (msgbuf == NULL) {
249 + dlpi_raise_exception(DL_SYSERR);
250 + return (NULL);
252 + saddrlen = DLPI_PHYSADDR_MAX;
253 + saddr = malloc(saddrlen);
254 + if (saddr == NULL) {
255 + dlpi_raise_exception(DL_SYSERR);
256 + free(msgbuf);
257 + return (NULL);
259 + msglenp = &msglen;
260 + saddrlenp = &saddrlen;
263 + if ((rval = dlpi_recv(link->dlpihdl, saddr, saddrlenp, msgbuf,
264 + msglenp, msec, NULL)) != DLPI_SUCCESS) {
265 + if (msgbuf != NULL)
266 + free(msgbuf);
267 + if (saddr != NULL)
268 + free(saddr);
269 + dlpi_raise_exception(rval);
270 + return (NULL);
273 + obj = Py_BuildValue("s#s#", saddr, saddrlen, msgbuf, msglen);
274 + if (msgbuf != NULL)
275 + free(msgbuf);
276 + if (saddr != NULL)
277 + free(saddr);
278 + return (obj);
281 +PyDoc_STRVAR(disabmulti_doc,
282 + "disabmulti(address) -> None\n"
283 + "\n"
284 + "Disable a specified multicast address on this link.\n"
285 + "See dlpi_disabmulti(3DLPI).\n"
287 +static PyObject *
288 +link_disabmulti(pylink_t *link, PyObject *args, PyObject *kwds)
290 + char *addr = NULL;
291 + size_t addrlen = 0;
292 + static char *keywords[] = {"address", NULL};
293 + int rval;
295 + if (link->dlpihdl == NULL) {
296 + errno = EINVAL;
297 + dlpi_raise_exception(DL_SYSERR);
298 + return (NULL);
301 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#", keywords,
302 + &addr, &addrlen))
303 + return (NULL);
305 + if ((addrlen == 0) || (addrlen > DLPI_PHYSADDR_MAX)) {
306 + errno = EINVAL;
307 + dlpi_raise_exception(DL_SYSERR);
308 + return (NULL);
311 + if ((rval = dlpi_disabmulti(link->dlpihdl, addr, addrlen)) !=
312 + DLPI_SUCCESS) {
313 + dlpi_raise_exception(rval);
314 + return (NULL);
317 + Py_INCREF(Py_None);
318 + return (Py_None);
321 +PyDoc_STRVAR(enabmulti_doc,
322 + "enabmulti(address) -> None\n"
323 + "\n"
324 + "Enable a specified multicast address on this link.\n"
325 + "See dlpi_enabmulti(3DLPI).\n"
327 +static PyObject *
328 +link_enabmulti(pylink_t *link, PyObject *args, PyObject *kwds)
330 + char *addr = NULL;
331 + size_t addrlen = 0;
332 + static char *keywords[] = {"address", NULL};
333 + int rval;
335 + if (link->dlpihdl == NULL) {
336 + errno = EINVAL;
337 + dlpi_raise_exception(DL_SYSERR);
338 + return (NULL);
341 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#", keywords,
342 + &addr, &addrlen))
343 + return (NULL);
345 + if ((addrlen == 0) || (addrlen > DLPI_PHYSADDR_MAX)) {
346 + errno = EINVAL;
347 + dlpi_raise_exception(DL_SYSERR);
348 + return (NULL);
351 + if ((rval = dlpi_enabmulti(link->dlpihdl, addr, addrlen)) !=
352 + DLPI_SUCCESS) {
353 + dlpi_raise_exception(rval);
354 + return (NULL);
357 + Py_INCREF(Py_None);
358 + return (Py_None);
361 +static void
362 +dlpi_callback(dlpi_handle_t hdl, dlpi_notifyinfo_t *ni, void *arg)
364 + callback_data_t *cd = (callback_data_t *)arg;
365 + PyObject *arglist, *result;
367 + switch (ni->dni_note) {
368 + case DL_NOTE_SPEED:
369 + arglist = Py_BuildValue("(OII)",
370 + cd->pyarg, ni->dni_note, ni->dni_speed);
371 + break;
372 + case DL_NOTE_SDU_SIZE:
373 + arglist = Py_BuildValue("(OII)",
374 + cd->pyarg, ni->dni_note, ni->dni_size);
375 + break;
376 + case DL_NOTE_PHYS_ADDR:
377 + arglist = Py_BuildValue("(OIs#)",
378 + cd->pyarg, ni->dni_note, ni->dni_physaddr,
379 + ni->dni_physaddrlen);
380 + break;
381 + default:
382 + arglist = Py_BuildValue("(OIO)", cd->pyarg, ni->dni_note,
383 + Py_None);
386 + result = PyEval_CallObject(cd->pyfunc, arglist);
387 + Py_DECREF(arglist);
388 + if (result == NULL) {
389 + PyErr_Clear(); /* cannot raise error */
391 + Py_DECREF(result);
392 + Py_DECREF(cd->pyfunc);
393 + Py_XDECREF(cd->pyarg);
394 + free(cd);
397 +PyDoc_STRVAR(enabnotify_doc,
398 + "enabnotify(events, function[, arg]) -> unsigned long\n"
399 + "\n"
400 + "Enables a notification callback for the set of specified events,\n"
401 + "which must be one or more (by a logical OR) events listed as below:\n"
402 + "NOTE_LINK_DOWN Notify when link has gone down\n"
403 + "NOTE_LINK_UP Notify when link has come up\n"
404 + "NOTE_PHYS_ADDR Notify when address changes\n"
405 + "NOTE_SDU_SIZE Notify when MTU changes\n"
406 + "NOTE_SPEED Notify when speed changes\n"
407 + "NOTE_PROMISC_ON_PHYS Notify when PROMISC_PHYS is set\n"
408 + "NOTE_PROMISC_OFF_PHYS Notify when PROMISC_PHYS is cleared\n"
409 + "Returns a handle for this registration.\n"
410 + "See dlpi_enabnotify(3DLPI).\n"
412 +static PyObject *
413 +link_enabnotify(pylink_t *link, PyObject *args, PyObject *kwds)
415 + PyObject *func = NULL, *arg = NULL;
416 + callback_data_t *cd;
417 + uint_t notes = 0;
418 + static char *keywords[] = {"events", "function", "arg", NULL};
419 + dlpi_notifyid_t id;
420 + int rval;
422 + if (link->dlpihdl == NULL) {
423 + errno = EINVAL;
424 + dlpi_raise_exception(DL_SYSERR);
425 + return (NULL);
428 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "IO|O",
429 + keywords, &notes, &func, &arg))
430 + return (NULL);
432 + if (!PyCallable_Check(func)) {
433 + errno = EINVAL;
434 + dlpi_raise_exception(DL_SYSERR);
435 + return (NULL);
438 + cd = malloc(sizeof(callback_data_t));
439 + if (cd == NULL) {
440 + dlpi_raise_exception(DL_SYSERR);
441 + return (NULL);
443 + Py_INCREF(func);
444 + Py_XINCREF(arg);
445 + cd->pyfunc = func;
446 + cd->pyarg = arg;
448 + if ((rval = dlpi_enabnotify(link->dlpihdl, notes, dlpi_callback,
449 + cd, &id)) != DLPI_SUCCESS) {
450 + free(cd);
451 + Py_DECREF(func);
452 + Py_XDECREF(arg);
453 + dlpi_raise_exception(rval);
454 + return (NULL);
457 + return (Py_BuildValue("k", id));
460 +PyDoc_STRVAR(disabnotify_doc,
461 + "disabnotify(handle) -> argument object, or None\n"
462 + "\n"
463 + "Disables the notification registration associated with handle.\n"
464 + "You should get this handle by calling enabnotify().\n"
465 + "Returns the argument passed in when registering the callback, or None.\n"
466 + "See dlpi_disabnotify(3DLPI).\n"
468 +static PyObject *
469 +link_disabnotify(pylink_t *link, PyObject *args, PyObject *kwds)
471 + dlpi_notifyid_t id;
472 + callback_data_t *arg;
473 + PyObject *pyargsaved;
474 + static char *keywords[] = {"handle", NULL};
475 + int rval;
477 + if (link->dlpihdl == NULL) {
478 + errno = EINVAL;
479 + dlpi_raise_exception(DL_SYSERR);
480 + return (NULL);
483 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "k", keywords, &id))
484 + return (NULL);
486 + if ((rval = dlpi_disabnotify(link->dlpihdl, id, (void **)&arg)) !=
487 + DLPI_SUCCESS) {
488 + dlpi_raise_exception(rval);
489 + return (NULL);
492 + /* clean up */
493 + pyargsaved = arg->pyarg;
494 + Py_XINCREF(pyargsaved);
495 + Py_XDECREF(arg->pyarg);
496 + Py_DECREF(arg->pyfunc);
497 + free(arg);
499 + if (pyargsaved != NULL)
500 + return (pyargsaved);
502 + Py_INCREF(Py_None);
503 + return (Py_None);
506 +PyDoc_STRVAR(get_sap_doc,
507 + "get_sap() -> unsigned int\n"
508 + "\n"
509 + "Returns the sap bound to this link.\n"
510 + "See dlpi_info(3DLPI).\n"
512 +static PyObject *
513 +link_get_sap(pylink_t *link)
515 + dlpi_info_t info;
516 + int rval;
518 + if (link->dlpihdl == NULL) {
519 + errno = EINVAL;
520 + dlpi_raise_exception(DL_SYSERR);
521 + return (NULL);
524 + if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
525 + DLPI_SUCCESS) {
526 + dlpi_raise_exception(rval);
527 + return (NULL);
530 + return (Py_BuildValue("I", info.di_sap));
533 +PyDoc_STRVAR(get_fd_doc,
534 + "get_fd() -> int\n"
535 + "\n"
536 + "Returns the integer file descriptor that can be used to directly\n"
537 + "operate on the link.\n"
538 + "See dlpi_fd(3DLPI).\n"
540 +static PyObject *
541 +link_get_fd(pylink_t *link)
543 + int fd;
545 + if (link->dlpihdl == NULL) {
546 + errno = EINVAL;
547 + dlpi_raise_exception(DL_SYSERR);
548 + return (NULL);
551 + if ((fd = dlpi_fd(link->dlpihdl)) == -1) {
552 + dlpi_raise_exception(DL_SYSERR);
553 + return (NULL);
556 + return (Py_BuildValue("i", fd));
559 +PyDoc_STRVAR(get_linkname_doc,
560 + "get_linkname() -> string\n"
561 + "\n"
562 + "Returns the name of the link.\n"
563 + "See dlpi_linkname(3DLPI).\n"
565 +static PyObject *
566 +link_get_linkname(pylink_t *link)
568 + const char *name = NULL;
570 + if (link->dlpihdl == NULL) {
571 + errno = EINVAL;
572 + dlpi_raise_exception(DL_SYSERR);
573 + return (NULL);
576 + if ((name = dlpi_linkname(link->dlpihdl)) == NULL) {
577 + dlpi_raise_exception(DL_SYSERR);
578 + return (NULL);
581 + return (Py_BuildValue("s", name));
584 +PyDoc_STRVAR(get_bcastaddr_doc,
585 + "get_bcastaddr() -> string, or None\n"
586 + "\n"
587 + "Returns the broadcast address of the link.\n"
588 + "Returns None if the broadcast address is empty.\n"
589 + "See dlpi_info(3DLPI).\n"
591 +static PyObject *
592 +link_get_bcastaddr(pylink_t *link)
594 + char *addr[DLPI_PHYSADDR_MAX];
595 + size_t addrlen = 0;
596 + dlpi_info_t info;
597 + int rval;
599 + if (link->dlpihdl == NULL) {
600 + errno = EINVAL;
601 + dlpi_raise_exception(DL_SYSERR);
602 + return (NULL);
605 + if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
606 + DLPI_SUCCESS) {
607 + dlpi_raise_exception(rval);
608 + return (NULL);
611 + if (info.di_bcastaddrlen == 0) {
612 + Py_INCREF(Py_None);
613 + return (Py_None);
616 + return (Py_BuildValue("s#", info.di_bcastaddr, info.di_bcastaddrlen));
619 +PyDoc_STRVAR(get_physaddr_doc,
620 + "get_physaddr(addrtype) -> string, or None\n"
621 + "\n"
622 + "Addrtype can be any one of the value listed below:\n"
623 + "FACT_PHYS_ADDR Factory physical address\n"
624 + "CURR_PHYS_ADDR Current physical address\n"
625 + "Returns the corresponding physical address of the link.\n"
626 + "See dlpi_get_physaddr(3DLPI).\n"
628 +static PyObject *
629 +link_get_physaddr(pylink_t *link, PyObject *args, PyObject *kwds)
631 + char *addr[DLPI_PHYSADDR_MAX];
632 + size_t addrlen = DLPI_PHYSADDR_MAX;
633 + static char *keywords[] = {"addrtype", NULL};
634 + uint_t type;
635 + int rval;
637 + if (link->dlpihdl == NULL) {
638 + errno = EINVAL;
639 + dlpi_raise_exception(DL_SYSERR);
640 + return (NULL);
643 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &type))
644 + return (NULL);
646 + if ((rval = dlpi_get_physaddr(link->dlpihdl, type, addr, &addrlen)) !=
647 + DLPI_SUCCESS) {
648 + dlpi_raise_exception(rval);
649 + return (NULL);
652 + return (Py_BuildValue("s#", addr, addrlen));
655 +PyDoc_STRVAR(set_physaddr_doc,
656 + "set_physaddr(address) -> None\n"
657 + "\n"
658 + "Sets the physical address of the link.\n"
659 + "See dlpi_set_physaddr(3DLPI).\n"
661 +static PyObject *
662 +link_set_physaddr(pylink_t *link, PyObject *args, PyObject *kwds)
664 + char *addr = NULL;
665 + size_t addrlen = 0;
666 + static char *keywords[] = {"address", NULL};
667 + int rval;
669 + if (link->dlpihdl == NULL) {
670 + errno = EINVAL;
671 + dlpi_raise_exception(DL_SYSERR);
672 + return (NULL);
675 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#", keywords,
676 + &addr, &addrlen))
677 + return (NULL);
679 + if ((rval = dlpi_set_physaddr(link->dlpihdl, DL_CURR_PHYS_ADDR,
680 + addr, addrlen)) != DLPI_SUCCESS) {
681 + dlpi_raise_exception(rval);
682 + return (NULL);
685 + Py_INCREF(Py_None);
686 + return (Py_None);
689 +PyDoc_STRVAR(promiscon_doc,
690 + "promiscon([level]) -> None\n"
691 + "\n"
692 + "Enables promiscuous mode for the link at levels:\n"
693 + "PROMISC_PHYS Promiscuous mode at the physical level(default)\n"
694 + "PROMISC_SAP Promiscuous mode at the SAP level\n"
695 + "PROMISC_MULTI Promiscuous mode for all multicast addresses\n"
696 + "See dlpi_promiscon(3DLPI).\n"
698 +static PyObject *
699 +link_promiscon(pylink_t *link, PyObject *args, PyObject *kwds)
701 + uint_t level = DL_PROMISC_PHYS;
702 + static char *keywords[] = {"level", NULL};
703 + int rval;
705 + if (link->dlpihdl == NULL) {
706 + errno = EINVAL;
707 + dlpi_raise_exception(DL_SYSERR);
708 + return (NULL);
711 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|I", keywords, &level))
712 + return (NULL);
714 + if ((rval = dlpi_promiscon(link->dlpihdl, level)) != DLPI_SUCCESS) {
715 + dlpi_raise_exception(rval);
716 + return (NULL);
719 + Py_INCREF(Py_None);
720 + return (Py_None);
723 +PyDoc_STRVAR(promiscoff_doc,
724 + "promiscoff([level]) -> None\n"
725 + "\n"
726 + "Disables promiscuous mode for the link at levels:\n"
727 + "PROMISC_PHYS Promiscuous mode at the physical level(default)\n"
728 + "PROMISC_SAP Promiscuous mode at the SAP level\n"
729 + "PROMISC_MULTI Promiscuous mode for all multicast addresses\n"
730 + "See dlpi_promiscoff(3DLPI).\n"
732 +static PyObject *
733 +link_promiscoff(pylink_t *link, PyObject *args, PyObject *kwds)
735 + uint_t level = DL_PROMISC_PHYS;
736 + static char *keywords[] = {"level", NULL};
737 + int rval;
739 + if (link->dlpihdl == NULL) {
740 + errno = EINVAL;
741 + dlpi_raise_exception(DL_SYSERR);
742 + return (NULL);
745 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|I", keywords, &level))
746 + return (NULL);
748 + if ((rval = dlpi_promiscoff(link->dlpihdl, level)) != DLPI_SUCCESS) {
749 + dlpi_raise_exception(rval);
750 + return (NULL);
753 + Py_INCREF(Py_None);
754 + return (Py_None);
757 +PyDoc_STRVAR(get_timeout_doc,
758 + "get_timeout() -> int\n"
759 + "\n"
760 + "Returns current time out value of the link.\n"
761 + "See dlpi_info(3DLPI).\n"
763 +static PyObject *
764 +link_get_timeout(pylink_t *link)
766 + dlpi_info_t info;
767 + int rval;
769 + if (link->dlpihdl == NULL) {
770 + errno = EINVAL;
771 + dlpi_raise_exception(DL_SYSERR);
772 + return (NULL);
775 + if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
776 + DLPI_SUCCESS) {
777 + dlpi_raise_exception(rval);
778 + return (NULL);
781 + return (Py_BuildValue("i", info.di_timeout));
784 +PyDoc_STRVAR(get_mactype_doc,
785 + "get_mactype() -> unsigned char\n"
786 + "\n"
787 + "Returns MAC type of the link.\n"
788 + "See <sys/dlpi.h> for the list of possible MAC types.\n"
789 + "See dlpi_info(3DLPI).\n"
791 +static PyObject *
792 +link_get_mactype(pylink_t *link)
794 + dlpi_info_t info;
795 + int rval;
797 + if (link->dlpihdl == NULL) {
798 + errno = EINVAL;
799 + dlpi_raise_exception(DL_SYSERR);
800 + return (NULL);
803 + if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
804 + DLPI_SUCCESS) {
805 + dlpi_raise_exception(rval);
806 + return (NULL);
809 + return (Py_BuildValue("B", info.di_mactype));
812 +PyDoc_STRVAR(set_timeout_doc,
813 + "set_timeout(timeout) -> None\n"
814 + "\n"
815 + "Sets time out value of the link (default value: DEF_TIMEOUT).\n"
816 + "See dlpi_set_timeout(3DLPI).\n"
818 +static PyObject *
819 +link_set_timeout(pylink_t *link, PyObject *args, PyObject *kwds)
821 + int timeout = DLPI_DEF_TIMEOUT;
822 + static char *keywords[] = {"timeout", NULL};
823 + int rval;
825 + if (link->dlpihdl == NULL) {
826 + errno = EINVAL;
827 + dlpi_raise_exception(DL_SYSERR);
828 + return (NULL);
831 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", keywords, &timeout))
832 + return (NULL);
834 + if ((rval = dlpi_set_timeout(link->dlpihdl, timeout)) != DLPI_SUCCESS) {
835 + dlpi_raise_exception(rval);
836 + return (NULL);
839 + Py_INCREF(Py_None);
840 + return (Py_None);
843 +PyDoc_STRVAR(get_sdu_doc,
844 + "get_sdu() -> (unsigned int, unsigned int)\n"
845 + "\n"
846 + "Returns (min sdu, max sdu).\n"
847 + "See dlpi_info(3DLPI).\n"
849 +static PyObject *
850 +link_get_sdu(pylink_t *link)
852 + dlpi_info_t info;
853 + int rval;
855 + if (link->dlpihdl == NULL) {
856 + errno = EINVAL;
857 + dlpi_raise_exception(DL_SYSERR);
858 + return (NULL);
861 + if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
862 + DLPI_SUCCESS) {
863 + dlpi_raise_exception(rval);
864 + return (NULL);
867 + return (Py_BuildValue("II", info.di_min_sdu, info.di_max_sdu));
870 +PyDoc_STRVAR(get_state_doc,
871 + "get_state() -> unsigned int\n"
872 + "\n"
873 + "Returns current state of the link (either UNBOUND or IDLE).\n"
874 + "See dlpi_info(3DLPI).\n"
876 +static PyObject *
877 +link_get_state(pylink_t *link)
879 + dlpi_info_t info;
880 + int rval;
882 + if (link->dlpihdl == NULL) {
883 + errno = EINVAL;
884 + dlpi_raise_exception(DL_SYSERR);
885 + return (NULL);
888 + if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
889 + DLPI_SUCCESS) {
890 + dlpi_raise_exception(rval);
891 + return (NULL);
894 + return (Py_BuildValue("I", info.di_state));
897 +PyDoc_STRVAR(get_qos_select_doc,
898 + "get_qos_select() -> (unsigned int, int, int, int)\n"
899 + "\n"
900 + "Returns (qos type, trans delay, priority, residul err).\n"
901 + "Unsupported QOS parameters are set to UNKNOWN.\n"
902 + "See dlpi_info(3DLPI).\n"
904 +static PyObject *
905 +link_get_qos_select(pylink_t *link)
907 + dlpi_info_t info;
908 + int rval;
910 + if (link->dlpihdl == NULL) {
911 + errno = EINVAL;
912 + dlpi_raise_exception(DL_SYSERR);
913 + return (NULL);
916 + if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
917 + DLPI_SUCCESS) {
918 + dlpi_raise_exception(rval);
919 + return (NULL);
922 + return (Py_BuildValue("Iiiii",
923 + info.di_qos_sel.dl_qos_type,
924 + info.di_qos_sel.dl_trans_delay,
925 + info.di_qos_sel.dl_priority,
926 + info.di_qos_sel.dl_residual_error));
929 +PyDoc_STRVAR(get_qos_range_doc,
930 + "get_qos_range() -> \n"
931 + " (unsigned int, (int, int), (int, int), (int, int), int)\n"
932 + "\n"
933 + "Returns (qos type, (trans delay target, trans delay accept),\n"
934 + "(min priority, max priority), (min protection, max protection),\n"
935 + "residual err).\n"
936 + "Unsupported QOS range values are set to UNKNOWN.\n"
937 + "See dlpi_info(3DLPI).\n"
939 +static PyObject *
940 +link_get_qos_range(pylink_t *link)
942 + dlpi_info_t info;
943 + int rval;
945 + if (link->dlpihdl == NULL) {
946 + errno = EINVAL;
947 + dlpi_raise_exception(DL_SYSERR);
948 + return (NULL);
951 + if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
952 + DLPI_SUCCESS) {
953 + dlpi_raise_exception(rval);
954 + return (NULL);
957 + return (Py_BuildValue("I(ii)(ii)(ii)i",
958 + info.di_qos_range.dl_qos_type,
959 + info.di_qos_range.dl_trans_delay.dl_target_value,
960 + info.di_qos_range.dl_trans_delay.dl_accept_value,
961 + info.di_qos_range.dl_priority.dl_min,
962 + info.di_qos_range.dl_priority.dl_max,
963 + info.di_qos_range.dl_protection.dl_min,
964 + info.di_qos_range.dl_protection.dl_max,
965 + info.di_qos_range.dl_residual_error));
968 +static PyMethodDef pylink_methods[] = {
969 + {"bind", (PyCFunction)link_bind, METH_VARARGS|METH_KEYWORDS, bind_doc},
970 + {"unbind", (PyCFunction)link_unbind, METH_NOARGS, unbind_doc},
971 + {"send", (PyCFunction)link_send, METH_VARARGS|METH_KEYWORDS,
972 + send_doc},
973 + {"recv", (PyCFunction)link_recv, METH_VARARGS|METH_KEYWORDS,
974 + recv_doc},
975 + {"disabmulti", (PyCFunction)link_disabmulti, METH_VARARGS|METH_KEYWORDS,
976 + disabmulti_doc},
977 + {"enabmulti", (PyCFunction)link_enabmulti, METH_VARARGS|METH_KEYWORDS,
978 + enabmulti_doc},
979 + {"enabnotify", (PyCFunction)link_enabnotify,
980 + METH_VARARGS|METH_KEYWORDS, enabnotify_doc},
981 + {"disabnotify", (PyCFunction)link_disabnotify,
982 + METH_VARARGS|METH_KEYWORDS, disabnotify_doc},
983 + {"get_fd", (PyCFunction)link_get_fd, METH_NOARGS, get_fd_doc},
984 + {"get_sap", (PyCFunction)link_get_sap, METH_NOARGS, get_sap_doc},
985 + {"get_mactype", (PyCFunction)link_get_mactype, METH_NOARGS,
986 + get_mactype_doc},
987 + {"get_linkname", (PyCFunction)link_get_linkname, METH_NOARGS,
988 + get_linkname_doc},
989 + {"get_bcastaddr", (PyCFunction)link_get_bcastaddr, METH_NOARGS,
990 + get_bcastaddr_doc},
991 + {"get_physaddr", (PyCFunction)link_get_physaddr,
992 + METH_VARARGS|METH_KEYWORDS, get_physaddr_doc},
993 + {"set_physaddr", (PyCFunction)link_set_physaddr,
994 + METH_VARARGS|METH_KEYWORDS, set_physaddr_doc},
995 + {"promiscon", (PyCFunction)link_promiscon, METH_VARARGS|METH_KEYWORDS,
996 + promiscon_doc},
997 + {"promiscoff", (PyCFunction)link_promiscoff, METH_VARARGS|METH_KEYWORDS,
998 + promiscoff_doc},
999 + {"get_timeout", (PyCFunction)link_get_timeout, METH_NOARGS,
1000 + get_timeout_doc},
1001 + {"set_timeout", (PyCFunction)link_set_timeout,
1002 + METH_VARARGS|METH_KEYWORDS, set_timeout_doc},
1003 + {"get_sdu", (PyCFunction)link_get_sdu, METH_NOARGS, get_sdu_doc},
1004 + {"get_state", (PyCFunction)link_get_state, METH_NOARGS,
1005 + get_state_doc},
1006 + {"get_qos_select", (PyCFunction)link_get_qos_select, METH_NOARGS,
1007 + get_qos_select_doc},
1008 + {"get_qos_range", (PyCFunction)link_get_qos_range, METH_NOARGS,
1009 + get_qos_range_doc},
1010 + {NULL}
1013 +static PyTypeObject pylink_type = {
1014 + PyObject_HEAD_INIT(0) /* Must fill in type value later */
1015 + 0, /* ob_size */
1016 + "dlpi.link", /* tp_name */
1017 + sizeof(pylink_t), /* tp_basicsize */
1018 + 0, /* tp_itemsize */
1019 + (destructor)link_dealloc, /* tp_dealloc */
1020 + 0, /* tp_print */
1021 + 0, /* tp_getattr */
1022 + 0, /* tp_setattr */
1023 + 0, /* tp_compare */
1024 + 0, /* tp_repr */
1025 + 0, /* tp_as_number */
1026 + 0, /* tp_as_sequence */
1027 + 0, /* tp_as_mapping */
1028 + 0, /* tp_hash */
1029 + 0, /* tp_call */
1030 + 0, /* tp_str */
1031 + 0, /* tp_getattro */
1032 + 0, /* tp_setattro */
1033 + 0, /* tp_as_buffer */
1034 + Py_TPFLAGS_DEFAULT, /* tp_flags */
1035 + link_doc, /* tp_doc */
1036 + 0, /* tp_traverse */
1037 + 0, /* tp_clear */
1038 + 0, /* tp_richcompare */
1039 + 0, /* tp_weaklistoffset */
1040 + 0, /* tp_iter */
1041 + 0, /* tp_iternext */
1042 + pylink_methods, /* tp_methods */
1043 + 0, /* tp_members */
1044 + 0, /* tp_getset */
1045 + 0, /* tp_base */
1046 + 0, /* tp_dict */
1047 + 0, /* tp_descr_get */
1048 + 0, /* tp_descr_set */
1049 + 0, /* tp_dictoffset */
1050 + (initproc)link_init, /* tp_init */
1051 + 0, /* tp_alloc */
1052 + PyType_GenericNew, /* tp_new */
1053 + 0, /* tp_free */
1056 +PyDoc_STRVAR(arptype_doc,
1057 + "arptype(arptype) -> unsigned int\n"
1058 + "\n"
1059 + "Converts a DLPI MAC type to an ARP hardware type defined\n"
1060 + " in <netinet/arp.h>\n"
1061 + "See dlpi_arptype(3DLPI)\n"
1063 +static PyObject *
1064 +arptype(PyObject *dlpi, PyObject *args, PyObject *kwds)
1066 + static char *keywords[] = {"arptype", NULL};
1067 + uint_t dlpityp, arptyp;
1069 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &dlpityp))
1070 + return (NULL);
1072 + if ((arptyp = dlpi_arptype(dlpityp)) == 0) {
1073 + errno = EINVAL;
1074 + dlpi_raise_exception(DL_SYSERR);
1075 + return (NULL);
1078 + return (Py_BuildValue("I", arptyp));
1081 +PyDoc_STRVAR(iftype_doc,
1082 + "iftype(iftype) -> unsigned int\n"
1083 + "\n"
1084 + "Converts a DLPI MAC type to a BSD socket interface type\n"
1085 + "defined in <net/if_types.h>\n"
1086 + "See dlpi_iftype(3DLPI)\n"
1088 +static PyObject *
1089 +iftype(PyObject *dlpi, PyObject *args, PyObject *kwds)
1091 + static char *keywords[] = {"iftype", NULL};
1092 + uint_t dlpityp, iftyp;
1094 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &dlpityp))
1095 + return (NULL);
1097 + if ((iftyp = dlpi_iftype(dlpityp)) == 0) {
1098 + errno = EINVAL;
1099 + dlpi_raise_exception(DL_SYSERR);
1100 + return (NULL);
1103 + return (Py_BuildValue("I", iftyp));
1106 +PyDoc_STRVAR(mactype_doc,
1107 + "mactype(mactype) -> string\n"
1108 + "\n"
1109 + "Returns a string that describes the specified mactype.\n"
1110 + "Valid mac types are defined in <sys/dlpi.h>.\n"
1111 + "See dlpi_mactype(3DLPI)\n"
1113 +static PyObject *
1114 +mactype(PyObject *dlpi, PyObject *args, PyObject *kwds)
1116 + static char *keywords[] = {"mactype", NULL};
1117 + uint_t mactyp;
1119 + if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &mactyp))
1120 + return (NULL);
1122 + return (Py_BuildValue("s", dlpi_mactype(mactyp)));
1125 +static boolean_t
1126 +link_walker(const char *name, void *arg)
1128 + PyObject *linkname;
1129 + PyObject *list = (PyObject *)arg;
1131 + if ((list == NULL) || !PyList_Check(list))
1132 + return (_B_FALSE);
1134 + linkname = Py_BuildValue("s", name);
1135 + if (PyList_Append(list, linkname) == -1)
1136 + return (_B_TRUE);
1138 + Py_DECREF(linkname);
1139 + return (_B_FALSE);
1142 +PyDoc_STRVAR(listlink_doc,
1143 + "listlink() -> list\n"
1144 + "\n"
1145 + "Returns a list containing link names of all links on the system.\n"
1147 +static PyObject *
1148 +listlink(PyObject *dlpi)
1150 + PyObject *list;
1152 + if ((list = PyList_New(0)) == NULL)
1153 + return (NULL);
1155 + dlpi_walk(link_walker, list, 0);
1156 + return (list);
1159 +static PyMethodDef dlpi_methods[] = {
1160 + {"arptype", (PyCFunction)arptype, METH_VARARGS|METH_KEYWORDS,
1161 + arptype_doc},
1162 + {"iftype", (PyCFunction)iftype, METH_VARARGS|METH_KEYWORDS,
1163 + iftype_doc},
1164 + {"mactype", (PyCFunction)mactype, METH_VARARGS|METH_KEYWORDS,
1165 + mactype_doc},
1166 + {"listlink", (PyCFunction)listlink, METH_NOARGS, listlink_doc},
1167 + {NULL}
1170 +PyMODINIT_FUNC
1171 +initdlpi(void)
1173 + PyObject *mod;
1175 + if (PyType_Ready(&pylink_type) < 0)
1176 + return;
1178 + mod = Py_InitModule("dlpi", dlpi_methods);
1179 + if (mod == NULL)
1180 + return;
1182 + dlpi_err = PyErr_NewException("dlpi.error", NULL, NULL);
1183 + if (dlpi_err == NULL)
1184 + return;
1185 + PyModule_AddObject(mod, "error", dlpi_err);
1187 + Py_INCREF(&pylink_type);
1188 + PyModule_AddObject(mod, "link", (PyObject *)&pylink_type);
1189 + PyModule_AddIntConstant(mod, "PASSIVE", DLPI_PASSIVE);
1190 + PyModule_AddIntConstant(mod, "RAW", DLPI_RAW);
1191 + PyModule_AddIntConstant(mod, "NATIVE", DLPI_NATIVE);
1192 + PyModule_AddIntConstant(mod, "ANY_SAP", DLPI_ANY_SAP);
1193 + PyModule_AddIntConstant(mod, "DEF_TIMEOUT", DLPI_DEF_TIMEOUT);
1194 + PyModule_AddIntConstant(mod, "NOTE_LINK_DOWN", DL_NOTE_LINK_DOWN);
1195 + PyModule_AddIntConstant(mod, "NOTE_LINK_UP", DL_NOTE_LINK_UP);
1196 + PyModule_AddIntConstant(mod, "NOTE_PHYS_ADDR", DL_NOTE_PHYS_ADDR);
1197 + PyModule_AddIntConstant(mod, "NOTE_SDU_SIZE", DL_NOTE_SDU_SIZE);
1198 + PyModule_AddIntConstant(mod, "NOTE_SPEED", DL_NOTE_SPEED);
1199 + PyModule_AddIntConstant(mod, "NOTE_PROMISC_ON_PHYS",
1200 + DL_NOTE_PROMISC_ON_PHYS);
1201 + PyModule_AddIntConstant(mod, "NOTE_PROMISC_OFF_PHYS",
1202 + DL_NOTE_PROMISC_OFF_PHYS);
1203 + PyModule_AddIntConstant(mod, "FACT_PHYS_ADDR", DL_FACT_PHYS_ADDR);
1204 + PyModule_AddIntConstant(mod, "CURR_PHYS_ADDR", DL_CURR_PHYS_ADDR);
1205 + PyModule_AddIntConstant(mod, "PROMISC_PHYS", DL_PROMISC_PHYS);
1206 + PyModule_AddIntConstant(mod, "PROMISC_SAP", DL_PROMISC_SAP);
1207 + PyModule_AddIntConstant(mod, "PROMISC_MULTI", DL_PROMISC_MULTI);
1208 + PyModule_AddIntConstant(mod, "UNKNOWN", DL_UNKNOWN);
1209 + PyModule_AddIntConstant(mod, "UNBOUND", DL_UNBOUND);
1210 + PyModule_AddIntConstant(mod, "IDLE", DL_IDLE);
1211 + PyModule_AddIntConstant(mod, "SYSERR", DL_SYSERR);
1213 --- Python-2.7.6/setup.py.~3~ 2014-05-14 13:10:30.979598710 -0700
1214 +++ Python-2.7.6/setup.py 2014-05-14 13:10:31.006864446 -0700
1215 @@ -1543,6 +1543,12 @@
1216 else:
1217 missing.append('dl')
1219 + # dlpi module (Solaris)
1220 + dlpi_inc = find_file('libdlpi.h', [], inc_dirs)
1221 + if dlpi_inc is not None:
1222 + exts.append( Extension('dlpi', ['dlpimodule.c'],
1223 + libraries = ['dlpi']) )
1225 # Thomas Heller's _ctypes module
1226 self.detect_ctypes(inc_dirs, lib_dirs)
1228 --- /dev/null 2011-02-12 03:13:26.000000000 -0600
1229 +++ Python-2.6.4/Lib/test/dlpitest.py 2011-01-20 13:52:42.895865414 -0600
1230 @@ -0,0 +1,96 @@
1231 +#!/usr/bin/python2.7
1233 +import dlpi
1234 +import sys
1235 +import time
1236 +import struct
1238 +#test listlink
1239 +linklist = dlpi.listlink()
1240 +print "Found %d links:" % len(linklist)
1241 +print linklist
1243 +#pick up the first data link for below testing
1244 +linkname = linklist[0]
1246 +#open link
1247 +print "opening link: " + linkname + "..."
1248 +testlink = dlpi.link(linkname)
1250 +#read some info of testlink
1251 +print "linkname is %s" % testlink.get_linkname()
1252 +print "link fd is %d" % testlink.get_fd()
1253 +mactype = testlink.get_mactype()
1254 +print "dlpi mactype is %d" % mactype
1255 +print "after convert:"
1256 +print "\tmactype is %s" % dlpi.mactype(mactype)
1257 +print "\tiftype is %d" % dlpi.iftype(mactype)
1258 +print "\tarptype is %d" % dlpi.arptype(mactype)
1259 +bcastaddr = testlink.get_bcastaddr()
1260 +print "broadcast addr is: ",
1261 +print struct.unpack("BBBBBB",bcastaddr)
1262 +physaddr = testlink.get_physaddr(dlpi.FACT_PHYS_ADDR)
1263 +print "factory physical address is: ",
1264 +print struct.unpack("BBBBBB",physaddr)
1265 +print "current timeout value is %d" % testlink.get_timeout()
1266 +print "sdu is:",
1267 +print testlink.get_sdu()
1268 +print "qos select is:",
1269 +print testlink.get_qos_select()
1270 +print "qos range is:",
1271 +print testlink.get_qos_range()
1273 +#set some config value of testlink and read them again
1274 +print "setting current physiacal addr to aa:0:10:13:27:5"
1275 +testlink.set_physaddr('\xaa\0\x10\x13\x27\5')
1276 +physaddr = testlink.get_physaddr(dlpi.CURR_PHYS_ADDR)
1277 +print "current physical addr is: ",
1278 +print struct.unpack("BBBBBB",physaddr)
1279 +print "set timeout value to 6..."
1280 +testlink.set_timeout(6)
1281 +print "timeout value is %d" % testlink.get_timeout()
1283 +#test enable/disable multicast
1284 +print "enable/disable multicast address 1:0:5e:0:0:5"
1285 +testlink.enabmulti('\1\0\x5e\0\0\5')
1286 +testlink.disabmulti('\1\0\x5e\0\0\5')
1288 +#test bind
1289 +print "binding to SAP 0x9000..."
1290 +testlink.bind(0x9000)
1291 +print "sap is %x" % testlink.get_sap()
1292 +print "state is: %d" % testlink.get_state()
1294 +#test send
1295 +print "sending broadcast loopback packet..."
1296 +testlink.send(bcastaddr, '\0\1\2\3\4\5')
1298 +#test notify functionality
1299 +arg = "notification callback arg"
1300 +def notify(arg, notes, value):
1301 + print "NOTE_PROMISC_ON_PHYS notification received with arg: '%s'" % arg
1302 +print "enabled notification on NOTE_PROMISC_ON_PHYS"
1303 +id = testlink.enabnotify(dlpi.NOTE_PROMISC_ON_PHYS, notify, arg) #enable notification
1304 +testlink.promiscon() #trigger the event (will be seen while receiving pkt below)
1306 +#test receive
1307 +print "testing receiving..."
1308 +try:
1309 + testlink.recv(0, 0) #should see NOTE_PROMISC_ON_PHYS event here
1310 +except dlpi.error, err:
1311 + errnum, errinfo = err
1312 + if errnum == 10006:
1313 + pass #timeout error is expected here
1314 + else: #test fails if reach here
1315 + print "test failed",
1316 + print errnum,
1317 + print err
1319 +testlink.promiscoff()
1320 +testlink.disabnotify(id) #disable notification
1322 +#test unbind
1323 +print "unbinding..."
1324 +testlink.unbind()
1325 +print "sap is %x" % testlink.get_sap()
1326 +print "state is: %d" % testlink.get_state()