1/* 2 * $Id: DNS.xs 639 2007-05-25 12:00:15Z olaf $ 3 * 4 * 5 * Copyright (c) 2005 Olaf Kolkman 6 * Copyright (c) 2002-2003 Chris Reinhardt. 7 * 8 * All rights reserved. This program is free software; you may redistribute 9 * it and/or modify it under the same terms as Perl itself. 10 * 11 * 12 */ 13 14#ifdef _HPUX_SOURCE 15#define _SYS_MAGIC_INCLUDED 16#endif 17 18 19#include "EXTERN.h" 20#include "perl.h" 21#include "XSUB.h" 22 23#include "netdns.h" 24 25 26 27/* 28 * int netdns_dn_expand( char *msg, char *eomorig, 29 * char *comp_dn, char *exp_dn, 30 * int length); 31 * 32 * 33 * netdns_dn_expand 34 * netdns_dn_expand() expands the compressed domain name given by the 35 * pointer comp _dn into a full domain name. 36 * 37 * The compressed name is contained in 38 * a query or reply message; msg is a pointer to the beginning 39 * of that message. Expanded names are stored in the buffer 40 * referenced by the exp_dn buffer of size length , which should 41 * be large enough to hold the expanded result. 42 * 43 * netdns_dn_expand() returns the size of the compressed name, or -1 44 * if there was an error. 45 */ 46 47MODULE = Net::DNS PACKAGE = Net::DNS::Packet 48 49PROTOTYPES: DISABLE 50 51void 52dn_expand_XS(sv_buf, offset) 53 SV * sv_buf 54 int offset 55 56 PPCODE: 57 STRLEN len; 58 u_char * buf; 59 u_char name[MAXDNAME]; 60 int pos; 61 62 if (SvROK(sv_buf)) 63 sv_buf = SvRV(sv_buf); 64 65 buf = (u_char *) SvPV(sv_buf, len); 66 67 /* This is where we do the actual uncompressing magic. */ 68 pos = netdns_dn_expand(buf, buf+len , buf+offset, &name[0], MAXDNAME); 69 70 EXTEND(SP, 2); 71 72 if (pos < 0) { 73 PUSHs(sv_2mortal(newSVsv(&PL_sv_undef))); 74 PUSHs(sv_2mortal(newSVsv(&PL_sv_undef))); 75 } else { 76 PUSHs(sv_2mortal(newSVpv((const char *)name, 0))); 77 PUSHs(sv_2mortal(newSViv(pos + offset))); 78 } 79 80 XSRETURN(2); 81 82 83 84