File: DNS.xs

package info (click to toggle)
libnet-dns-perl 0.81-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,256 kB
  • sloc: perl: 8,349; ansic: 104; makefile: 9
file content (83 lines) | stat: -rw-r--r-- 1,768 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * $Id: DNS.xs 639 2007-05-25 12:00:15Z olaf $
 *
 *
 * Copyright (c) 2005 Olaf Kolkman
 * Copyright (c) 2002-2003 Chris Reinhardt.
 * 
 * All rights reserved.  This program is free software; you may redistribute
 * it and/or modify it under the same terms as Perl itself.
 *
 *  
 */

#ifdef _HPUX_SOURCE
#define _SYS_MAGIC_INCLUDED
#endif
 
 
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "netdns.h"



/*
 * int netdns_dn_expand( char *msg,  char *eomorig,
 *	       char *comp_dn,  char *exp_dn,
 *	      int length);
 *
 *	   
 * netdns_dn_expand
 *	 netdns_dn_expand() expands the compressed domain name	 given by the
 *	 pointer comp _dn into a full domain name.
 * 
 *       The compressed name is contained in
 *	 a	query or reply message; msg is a pointer to the beginning
 *	 of that message. Expanded names are  stored  in  the  buffer
 *	 referenced by the exp_dn buffer of size length , which should
 *	 be large enough to hold the expanded result.
 *
 *	 netdns_dn_expand() returns the size of the compressed name,  or  -1
 *	 if there was an error. 
 */

MODULE = Net::DNS PACKAGE = Net::DNS::Packet

PROTOTYPES: DISABLE

void
dn_expand_XS(sv_buf, offset) 
	SV * sv_buf
	int offset

  PPCODE:
	STRLEN len;
	u_char * buf;
	u_char name[MAXDNAME];
	int pos;
	
	if (SvROK(sv_buf)) 
		sv_buf = SvRV(sv_buf);
	
	buf = (u_char *) SvPV(sv_buf, len);
	
	/* This is where we do the actual uncompressing magic. */
	pos = netdns_dn_expand(buf, buf+len , buf+offset, &name[0], MAXDNAME);
	
	EXTEND(SP, 2);
	
	if (pos < 0) {
		PUSHs(sv_2mortal(newSVsv(&PL_sv_undef)));
		PUSHs(sv_2mortal(newSVsv(&PL_sv_undef)));
	} else {
		PUSHs(sv_2mortal(newSVpv((const char *)name, 0)));
		PUSHs(sv_2mortal(newSViv(pos + offset)));
	}
	
	XSRETURN(2);