summaryrefslogtreecommitdiff
path: root/net/netatalk/files/patch-macusers
blob: 763e5ec339af11a6de7e4c86d784eac4dde1746c (plain) (blame)
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
--- contrib/macusers/macusers.orig	Wed Aug 29 12:20:32 2001
+++ contrib/macusers/macusers	Sun Jun 17 01:47:44 2001
@@ -1,8 +1,8 @@
 #!/usr/bin/perl
-# $Id: macusers,v 1.4 2001/06/29 14:14:46 rufustfirefly Exp $
 
 use strict;
-use vars qw($MAC_PROCESS $PS_STR $MATCH_STR $ASIP_PORT $LSOF);
+use Socket;
+use vars qw($MAC_PROCESS $PS_STR $MATCH_STR $ASIP_PORT_NO $ASIP_PORT $LSOF);
 
 # Written for linux; may have to be modified for your brand of Unix.
 
@@ -25,10 +25,11 @@
         $PS_STR    = "-ef";
         $MATCH_STR = '\s*(\w+)\s+(\d+)\s+(\d+)\s+\d+\s+([\d\w:]+)';
 }
-$ASIP_PORT = "afpovertcp";
+$ASIP_PORT    = "afpovertcp";
+$ASIP_PORT_NO = 548;
 
 # Change to 0 if you don't have lsof
-$LSOF = 1;
+$LSOF = 0;
 my %mac = ();
 
 if ( $LSOF == 1 ) {
@@ -43,8 +44,25 @@
                 ($host) = ( $host =~ /(^[\w\d\-]+)/ );
                 $mac{$pid} = $host;
         }
-
+        print
+"PID      UID      Username         Name                 Logintime Mac\n";
         close(LSOF);
+}
+elsif ( $^O eq "freebsd" ) {
+        open( SOCKSTAT, "sockstat -4 | grep $MAC_PROCESS | grep -v grep |" );
+
+        while (<SOCKSTAT>) {
+                next if ( $_ !~ /$MAC_PROCESS/ );
+                $_ =~
+                  /\S+\s+\S+\s+(\d+)\s+\d+\s+[\w\d]+\s+[\d\.:]+\s+([\d\.]+)/;
+                my ( $pid, $addr, $host );
+                $pid  = $1;
+                $addr = $2;
+                $host =
+                  gethostbyaddr( pack( 'C4', split ( /\./, $addr ) ), AF_INET );
+                ($host) = ( $host =~ /(^[\w\d\-]+)/ );
+                $mac{$pid} = $host;
+        }
         print
 "PID      UID      Username         Name                 Logintime Mac\n";
 }